<template>
  <div class="login-box">
    <van-loading type="spinner" color="#1989fa" />
    <div>正在登录系统，请耐心等待</div>
  </div>
</template>

<script>
import Vue from 'vue'
import { Loading } from 'vant';
Vue.use(Loading);
export default {
    data() {
			return {
				      env: {
				        thirdApp: true,
				        wxWork: true,
				        dingtalk: false,
				      },

			}
		},
    mounted() {
			this.doOAuth2Login()
			// console.log(encodeURIComponent(window.location.origin));
			// console.log(window.location.origin);
		},
    methods: {
      	doOAuth2Login() {	
				        if (this.$route.query.oauth2LoginToken) {
				        //   this.thirdType = this.$route.query.thirdType
				          let token = this.$route.query.oauth2LoginToken
						console.log(token)
				        //   this.doThirdLogin(token)
						this.$router.push("/hello")

				        } else if (this.env.wxWork) {
				          this.doWechatEnterpriseOAuth2Login()
				        } 
			},
		doThirdLogin(token) {
				let param = {}
				 param.token = token
				this.ThirdLogin(param).then(res => {
					if (res.success) {
						this.loginSuccess()
					} else {
						this.requestFailed(res)
					}
				})
      },
      loginSuccess() {

				// let _path =   Vue.ls.get('redirect_url');
				// let query = Vue.ls.get('url_query');
				// Vue.ls.remove('redirect_url')
				// 	Vue.ls.remove('url_query')		
				// if (_path) {
				// 	this.$router.push({ path: _path, query:query });
				// } else {
				// 	this.$router.push('/home');
				// }
      },
      doWechatEnterpriseOAuth2Login() {
			let url ="http://192.168.153.241:9090" + "/sys/thirdLogin/oauth2/wechat_enterprise/login"
			url += `?state=${encodeURIComponent('http://192.168.153.241:8080')}`
			// console.log(window.location.origin)
			 window.location.href = url 
      },
      requestFailed(err) {
				this.$message.warning("登录失败")
			},
    }
}
</script>

<style>
  .login-box {
    height: 100%;
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-size: 0.2rem;
    color: #1989fa;

    overflow: hidden;
  }
</style>
